/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.mods.survival.entitysystem.systems;

import etherblocks.game.entitysystem.Entity;
import etherblocks.game.entitysystem.EntityMap;
import etherblocks.game.entitysystem.EntitySystem;
import etherblocks.mods.survival.entitysystem.components.*;
import java.util.List;

/**
 *
 * @author Philipp
 */
public class HealthSystem implements EntitySystem
{

    public void onNextFrameCalculation(EntityMap entityMap, float lastTimePerFrame) {
        List<Entity> entities = entityMap.getEntities(HealthComponent.class);
        for(Entity entity : entities)
        {
            HealthComponent health = entity.getComponent(HealthComponent.class);
            float healthValue = health.getHealth();
            healthValue += health.getRegeneration() * lastTimePerFrame;
            entity.setComponent(new HealthComponent(healthValue, health.getMaxHealth(), health.getRegeneration()));
            if(health.getHealth() <= 0)
            {
                entity.clearComponent(HealthComponent.class);
                System.out.println("dead");
            }
        }
    }
    
}
